
package pl.genapp.stocksense.libraries;

import com.google.ads.p;

import pl.genapp.appsense.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.AttributeSet;
import android.util.Log;

public class SentGraphArrow extends SentGraph {

	private Paint circle = new Paint();
	private Bitmap[] bitmapArray;
	
	public SentGraphArrow(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		circle = new Paint();
		circle.setAntiAlias(true);
		circle.setStyle(Paint.Style.FILL_AND_STROKE);
		circle.setColor(0xFFefeeef);
		
		bitmapArray = new Bitmap[6];
		
		bitmapArray[0] = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_6);
		bitmapArray[1] = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_1);
		bitmapArray[2] = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_2);
		bitmapArray[3] = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_3);
		bitmapArray[4] = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_4);
		bitmapArray[5] = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_5);
		
		
	}
	
	public void drawArrowsForSentiment(Canvas canvas, int sentNo, float sentValue) {
		
		float angle = -60 + 60 * sentNo;
		
		Matrix scale = new Matrix();
		scale.preScale((       (getGraphSize()/2)*0.3f  +  0.7f*(getGraphSize()/2)*sentValue*1.0f   )/bitmapArray[sentNo].getWidth(), 0.1f + 0.20f*sentValue);
		scale.postRotate(angle, 0, 0);
		
		Log.d("stocksense", bitmapArray[sentNo].getWidth() + " " + bitmapArray[sentNo].getHeight());
		
		Bitmap arrow = Bitmap.createBitmap(bitmapArray[sentNo], 0, 0, bitmapArray[sentNo].getWidth(), bitmapArray[sentNo].getHeight(), scale, true);
		
		 
		Point point = getPointOnCircumference(getGraphCenter()*1.0f, getGraphCenter()*1.0f, (int)angle - 30, (getGraphSize()/4.0f)* (Math.min(0.2f + sentValue, 1)));
				
		point.x -= getGraphCenter();
		point.y -= getGraphCenter();
		
		canvas.drawBitmap(arrow, getGraphCenter() - arrow.getWidth() / 2 + point.x, getGraphCenter() - arrow.getHeight() / 2 + point.y, circle);		
		
	
		canvas.drawCircle(getGraphCenter(), getGraphCenter(), 15, circle);
		
	}
	
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		
		for (int i = 0; i < 6; i++) {
				drawArrowsForSentiment(canvas, i, sentValues[i]);
		}
		
		if (getLegendRendered() != null) {
			getLegendRendered().drawLegend(canvas);
			
		}
	
	}
	
	
	
}
